Skip to content

task: stop at an interpreter error after the good lines have run - #4822

Open
revjmoney wants to merge 2 commits into
LinuxCNC:masterfrom
revjmoney:task-defer-read-error-abort
Open

revjmoney wants to merge 2 commits into
LinuxCNC:masterfrom
revjmoney:task-defer-read-error-abort

Conversation

@revjmoney

Copy link
Copy Markdown

Fixes #2978, using option 2 as @grandixximo chose: the good lines before an interpreter error run, then task aborts, with the error still shown.

Before: a read error (e.g. G4 X2, no P, fails check_items inside Interp::read) only set interpState = WAITING. The queued lines ran out and the program sat at the bad line with M3 still on. An execute error took the other extreme: interp_list.clear() and emcAbortCleanup() right away, which throws away the good lines read ahead of it and only resets the interpreter (no spindle or IO abort).

Now both paths do the same thing (emctaskmain.cc):

  1. Stop reading and set interp_error_pending. For an execute error, only what the bad line itself queued is dropped (InterpList::truncate, new, back to the length before that line); the good lines before it stay queued.
  2. In readahead_waiting, once interp_list, motion and IO are drained, run the same abort sequence task already uses for a motion/IO error: emcTaskAbort(), emcIoAbort(), emcSpindleAbort() per spindle, mdi_execute_abort(), then emcAbortCleanup(EMC_ABORT::INTERPRETER_ERROR).
  3. emcAbortCleanup clears the flag, so any other abort on the way (operator Abort, E-stop, machine off) cancels it.

The GUI is left alone (no blocking Run), as discussed.

Test: as suggested, two programs added to tests/motion-logger/basic with their expected logs: g4-no-p.ngc (the program from the issue) and exec-error.ngc (G83 Q0). Both now log the moves and SPINDLE_ON speed=1000 and then ABORT, SPINDLE_OFF. Before, g4-no-p ended at SPINDLE_ON speed=1000 with no stop, and exec-error logged nothing but SS_ENABLE (the good lines were dropped). The existing sub-tests (startup, reset, g0, g1, s) are unchanged. As you noted, the mock motion cannot tell "now" from "after the queue drains"; I left the halsampler variant out unless you want it.

Tested on a master run-in-place build (uspace, non-RT): tests/motion-logger 3/3, and the full scripts/runtests tests: 363 of 370 pass. The 7 failures are the five tests/ui-smoke GUI tests, which fail the same way on unpatched master on this box (missing GUI dependencies), and two interp tests from my other, unrelated branches that were left in the tree.

@grandixximo

Copy link
Copy Markdown
Contributor

@revjmoney please rebase there are conflicts after recent merges

A read error (G4 with no P fails check_items inside Interp::read) only
set interpState to WAITING. The lines queued before it ran out and the
program sat at the bad line with the spindle still on. An execute error
did the opposite: it cleared interp_list and reset the interpreter at
once, dropping the good lines read ahead of it, with no spindle or IO
abort.

Both now stop reading and set interp_error_pending. An execute error
drops only what the bad line itself queued (new InterpList::truncate).
Once interp_list, motion and IO have drained, readahead_waiting runs the
abort task already uses for a motion or IO error: emcTaskAbort,
emcIoAbort, emcSpindleAbort, mdi_execute_abort and emcAbortCleanup.
emcAbortCleanup clears the flag, so any abort on the way cancels it.

Adds g4-no-p.ngc (the program from the issue) and exec-error.ngc
(G83 Q0) to tests/motion-logger/basic.

Fixes LinuxCNC#2978.
The naive CAM detector holds feed moves back to join them, so the G1
right before a bad line was not in interp_list yet and was lost. Queue
the moves held from the lines before the error, and still drop what the
bad line itself queued or held. A bad line with an F word flushes the
held moves before it fails, so note where they end in interp_list.

In a run from line the moves queued and held at a read error are of
skipped lines. Drop them.

The abort could also come too early: with a copy of the status read
before the controller ran, traj.queue is still 0 after the last move
was sent, and a dwell or input wait only shows in execState. Wait for
both.

Adds tests/interp-error-abort, which uses the real motion controller.
@revjmoney

Copy link
Copy Markdown
Author

Rebased on master. While testing it on the real motion controller I found faults in my fix, so there is a second commit:

  • The G1 right before a bad line was lost, because canon still held it back to join it. It runs now.
  • A dwell right before a bad line was cut short. It runs to its end now.
  • The abort could come before the last move had run, the same stale traj.queue as in task: MDI is not finished while motion has yet to act on the move #4890. It waits for motion.status and execState now.
  • In a run from line, a read error in a skipped subroutine let a skipped G0 run. It is dropped now.

tests/interp-error-abort covers these. It takes about 3.5 minutes here, I can shorten it if that is too long for CI.

One limit: if the bad line queues or joins a move of its own before it fails, the moves held before it can still be dropped.

Full suite here: 383 of 388. The five failures (three touchy, two qtdragon in ui-smoke) also fail on plain master on this box.

@revjmoney
revjmoney force-pushed the task-defer-read-error-abort branch from 28d4a3a to 8e2fef7 Compare December 1, 2026 22:08
@BsAtHome

BsAtHome commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Full suite here: 383 of 388. The five failures (three touchy, two qtdragon in ui-smoke) also fail on plain master on this box.

That is a problem. Why do they fail?

@revjmoney

Copy link
Copy Markdown
Author

Missing packages on my box, not the code. The two qtdragon tests stop at "No module named 'qtpy'". The three touchy tests stop when gladevcp asks for GtkSource 4: "Namespace GtkSource not available".

All five passed here in CI, in both rip-and-test and rip-and-test-clang (388 of 388).

I have not installed the packages and rerun them on my box yet.

@revjmoney

Copy link
Copy Markdown
Author

Installed the missing packages and reran those five on my box with this branch's code: all five pass now, twice each. It needed python3-qtpy and python3-pyqt5.qsci for qtdragon, and gir1.2-gtksource-4 for touchy. I also put in python3-pyqt5.qtwebengine at the same time as qsci.

I have not rerun the full suite since.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue Parsing G4 Commands with Invalid Parameter

3 participants